# This Python file uses the following encoding: utf-8
import datetime
from google.appengine.ext import db

# Models.
class OrganisationType(models.Model):
    name = db.StringProperty(required=True)
    description = db.StringProperty(required=True)

def AddOrganisationType(name):
    ot=OrganisationType(name=name)
    ot.put()

class Organisation(models.Model):
    name = db.StringProperty(required=True)
    description = db.StringProperty(required=True)
    eid = db.StringProperty(required=True)
    otype = db.ReferenceProperty(OrganisationType)

def AddOrganisation(name,otype,eid):
    ot=OrganisationType(name=otype)
    o=Organisation(name=name,eid=eid,otype=ot)
    o.put()

class Person(models.Model):
    name = db.StringProperty(required=True)
    eid = db.StringProperty(required=True)
	
def AddPerson(name,eid):
    p=Person(name=name,eid=eid)
    p.put()

class Position(models.Model):
    person = db.ReferenceProperty(Person)
    organisation = db.ReferenceProperty(Organisation)
    position = db.StringProperty(required=True)
	
def AddPosition(name,org,pos):
    p=Person(name=name)
    o=Organisation(name=org)
    pos=Position(person=p,organisation=o,position=pos)
    pos.put()

class OrganisationLog(models.Model):
    date = db.DateProperty()
    organisation = db.ReferenceProperty(Organisation)
    pos = db.IntegerProperty()
    neg = db.IntegerProperty()
    neut = db.IntegerProperty()

class PersonLog(models.Model):
    date = db.DateProperty()
    person = db.ReferenceProperty(Person)
    pos = db.IntegerProperty()
    neg = db.IntegerProperty()
    neut = db.IntegerProperty()

class OrganisationVote(models.Model):
    uid = db.StringProperty(required=True)
    organisation = db.ReferenceProperty(Organisation)
    sentiment = db.IntegerProperty()

class PersonVote(models.Model):
    uid = db.StringProperty(required=True)
    person = db.ReferenceProperty(Person)
    sentiment = db.IntegerProperty()

def ClearModel():
	q=OrganisationType.all()
        db.delete(q)

	q=Organisation.all()
        db.delete(q)

	q=Person.all()
        db.delete(q)

	q=Position.all()
        db.delete(q)

	q=OrganisationLog.all()
        db.delete(q)

	q=PersonLog.all()
        db.delete(q)

	q=OrganisationVote.all()
        db.delete(q)

	q=PersonVote.all()
        db.delete(q)
# Methods
    


